<template>
    <!-- ParentDict新增、编辑对话框 -->
    <el-dialog
      :title="!addParentDictForm.dictTypeId ? '新增' : '修改'"
      :visible.sync="addParentDictdialog"
      width="50%">
      <el-form :model="addParentDictForm" :rules="addParentDictFormRules" ref="addParentDictFormRef" label-width="100px">
        <el-form-item label="类型编码" prop="code">
          <el-input v-model="addParentDictForm.code"></el-input>
        </el-form-item>
        <el-form-item label="分组名称" prop="dictTypeName">
          <el-input v-model="addParentDictForm.dictTypeName"></el-input>
        </el-form-item>
        <el-row>
          <el-col :span="6">
            <el-form-item label="状态" prop="status">
              <el-switch
                v-model="addParentDictForm.status"
                active-color="#409eff"
                inactive-color="#dcdfe6"
                active-value="1"
                inactive-value="0">
              </el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="系统字典" prop="isSystem">
              <el-switch
                v-model="addParentDictForm.isSystem"
                active-color="#409eff"
                inactive-color="#dcdfe6">
              </el-switch>
            </el-form-item>
          </el-col>
          <!-- <el-col :span="12">
            <el-form-item label="输入值类型" prop="inputType">
              <el-select v-model="addParentDictForm.inputType" placeholder="" style="width:100%">
                <el-option
                  v-for="item in inputType"
                  :key="item.value"
                  :label="item.name"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
        </el-row>
        <el-form-item label="备注" prop="description">
          <el-input
            type="textarea"
            :rows="2"
            placeholder="请输入内容"
            v-model="addParentDictForm.description"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addParentDictdialog = false">取 消</el-button>
        <el-button type="primary" @click="addParentPassValue()">确 定</el-button>
      </span>
    </el-dialog>
</template>

<script>
import {
  addDictData,
  addDictDataById
  // getParentDictTable
} from '@/api/auth/dict.js'
export default {
  data() {
    return {
      addParentDictdialog: false,
      addParentDictForm: {
        dictTypeId: '',
        dictTypeName: '',
        description: '',
        code: '',
        isSystem: 1,
        status: '1'
        // inputType: 'text'
      },
      addParentDictFormRules: {
        code: [
          { required: true, message: '请输入分组编码', trigger: 'blur' }
        ],
        isSystem: [
          { required: true, message: '请选择是否系统字典', trigger: 'blur' }
        ],
        dictTypeName: [
          { required: true, message: '请输入分组名称', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '请输入分组名称', trigger: 'blur' }
        ]
      },
      inputType: [
        { name: '文本', value: 'text' },
        { name: '多行文本', value: 'textare' },
        { name: '时间', value: 'time' },
        { name: '下拉框', value: 'select' }
      ]
    }
  },
  methods: {
    init(row, flag) {
      if (row.dictTypeId) { // 修改
        this.addParentDictForm = row
      } else { // 新增
        this.addParentDictForm.dictTypeId = ''
        this.clearForm()
      }
      this.addParentDictdialog = flag
    },
    clearForm() {
      this.addParentDictForm.dictTypeId = ''
      this.addParentDictForm.dictTypeName = ''
      this.addParentDictForm.description = ''
      this.addParentDictForm.code = ''
      this.addParentDictForm.isSystem = 1
      this.addParentDictForm.status = '1'
    },
    // 确定提交
    addParentPassValue() {
      this.$refs.addParentDictFormRef.validate(valid => {
        if (!valid) return
        if (this.addParentDictForm.dictTypeId) { // 修改
          addDictDataById(this.addParentDictForm).then((res) => {
            this.addParentDictdialog = false
            this.$emit('refreshParentDataList')
          })
        } else { // 新增
          addDictData(this.addParentDictForm).then(res => {
            this.$emit('refreshParentDataList')
          })
          this.addParentDictdialog = false
        }
      })
    }
  }
}
</script>

<style>
</style>
